// =======================================================================
// 
//       Filename:  plodder.hpp
// 
//    Description:  
// 
//        Version:  1.0
//        Created:  27.03.2010 18:00:28
//       Revision:  none
//       Compiler:  g++
// 
//         Author:  Dominik 'domachine' Burgdörfer (-), dominik.burgdoerfer@googlemail.com
//        Company:  -
// 
// =======================================================================


#ifndef  PLODDER_INC
#define  PLODDER_INC
#include <iostream>
#include <stdexcept>
#include <map>
#include <yaml.h>
#include "parser.hpp"
#include "processor.hpp"

namespace webplodder {
    class Plodder {
    public:
        /**
         * The config directory includes the config file
         * including the specifications for the script parsing.
         * @brief Constructs a Plodder up on a config directory.
         * @param[in] configDir This is the path of the config directory
         *            which includes a subdirectory `plugins'
         *            with all available Plugins.
         *            It also includes a config file with the
         *            script specifications
         */
        Plodder(const std::string& configDir);

        ~Plodder();

        /**
         * It parses the configfile in the configDir
         * @brief Initializes the Plodder.
         * @throw std::runtime_error Thrown if an error occurs
         *                           while opening or reading the
         *                           configfile
         * @throw YAML::Exception Thrown if an error occurs
         *          while parsing the configfile
         */
        void init();

        /**
         * Searches it for suitable
         * *.page and *.template files and processes
         * them.
         * @brief Scans a target directory.
         * @throw std::runtime_error Thrown if no *.page
         *                           or *.template file found
         */
        void scanDir(const std::string& dir);

        /**
         * NON means that nothing will be cached,
         * SCRIPT will cache all scripts and ALL
         * caches everything (very fast, but needs a huge
         * amount of memory. Depends on the size of the
         * template-file)
         * @brief Set cache mode.
         * @param cacheMode The cache mode to use.
         */
        void setCacheMode(Parser::CacheMode cacheMode);

    private:
        void scanPlugins();

        std::string mconfigDir;
        std::map<std::string,std::string> mscriptConfig;
        Parser::CacheMode mCacheMode;
        boost::shared_ptr<Processor> mProcessor;
    };
}
#endif   // ----- #ifndef PLODDER_INC  -----
